// UtilTest.cpp -- CppUnit tests of the Util functions
// Copyright (C) 2008  Morgan Conbere
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
// USA.
//
// $Id: UtilTest.cpp 19 2008-12-26 21:06:24Z mconbere $
//

#include <cppunit/extensions/HelperMacros.h>

#include "../Util.h"

class UtilTest : public CppUnit::TestFixture
{
    CPPUNIT_TEST_SUITE(UtilTest);
    CPPUNIT_TEST(testSwapUint16_t);
    CPPUNIT_TEST(testSwapInt16_t);
    CPPUNIT_TEST_SUITE_END();
    
public:
    void setUp() {}
    
    void tearDown() {}
    
    void testSwapUint16_t()
    {
        // Test a normal number
        uint16_t a = 0xAABB;
        uint16_t a_swapped = util::Swap(a);
        
        CPPUNIT_ASSERT(a_swapped == 0xBBAA);
        
        // Test a number with a 1 in the highest bit
        uint16_t b = 0xFF00;
        uint16_t b_swapped = util::Swap(b);
        
        CPPUNIT_ASSERT(b_swapped == 0x00FF);
        
        // Test a number with a 0 in the highest bit
        uint16_t c = 0x00FF;
        uint16_t c_swapped = util::Swap(c);
        
        CPPUNIT_ASSERT(c_swapped == 0xFF00);
    }
    
    void testSwapInt16_t()
    {
        // Test a normal number
        uint16_t a = 0xAABB;
        uint16_t a_swapped = util::Swap(a);
        
        CPPUNIT_ASSERT(a_swapped == 0xBBAA);
        
        // Test a number with a 1 in the highest bit
        uint16_t b = 0xFF00;
        uint16_t b_swapped = util::Swap(b);
        
        CPPUNIT_ASSERT(b_swapped == 0x00FF);
        
        // Test a number with a 0 in the highest bit
        uint16_t c = 0x00FF;
        uint16_t c_swapped = util::Swap(c);
        
        CPPUNIT_ASSERT(c_swapped == 0xFF00);
    }
};

CPPUNIT_TEST_SUITE_REGISTRATION(UtilTest);
